

package ejb.bank.utils;

import java.util.Random;



/**
 *  Klasa pomocnicza generujaca numer konta, 
 *  numer karty kredytowej, PIN
 *  
 * @author piotrek
 *
 */
public class Generator {
	
	private Random rand = new Random(System.currentTimeMillis());
	public static final String prefix = "23";
	
	public String generateAccountNumber() {
		
		StringBuilder sb = new StringBuilder();
		int tmp = 0;
		sb.append(prefix);
		for(int i = 0; i < 6; i++) {
			tmp = rand.nextInt(9999);
			if(tmp < 10) {
				sb.append("000" + tmp);
			} else if(tmp < 100) {
				sb.append("00" + tmp);
			} else if(tmp < 1000) {
				sb.append("0" + tmp);
			} else {
				sb.append(tmp);
			}
			tmp = 0;
		}
		
		return sb.toString();
	}
	
	
	public int generatePIN() {
		int pin = rand.nextInt(9999);
		if(pin < 1000) {
			pin += 1000;
		}
		return pin;
	}

}
